<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_participants=new participants();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["ID_PAR"])){$_participants->set_ID_PAR($_POST["ID_PAR"]);}
		if(isset($_POST["NOM_PAR"])){$_participants->set_NOM_PAR($_POST["NOM_PAR"]);}
		if(isset($_POST["PRENOM_PAR"])){$_participants->set_PRENOM_PAR($_POST["PRENOM_PAR"]);}
		if(isset($_POST["E_MAIL_PAR"])){$_participants->set_E_MAIL_PAR($_POST["E_MAIL_PAR"]);}
		if(isset($_POST["TEL_PAR"])){$_participants->set_TEL_PAR($_POST["TEL_PAR"]);}
		if(isset($_POST["GRADE_PAR"])){$_participants->set_GRADE_PAR($_POST["GRADE_PAR"]);}
		if(isset($_POST["SPECIALITE_PAR"])){$_participants->set_SPECIALITE_PAR($_POST["SPECIALITE_PAR"]);}
		if(isset($_POST["UNIVERSITE_PAR"])){$_participants->set_UNIVERSITE_PAR($_POST["UNIVERSITE_PAR"]);}
		if(isset($_POST["ETABLISSEMENT_PAR"])){$_participants->set_ETABLISSEMENT_PAR($_POST["ETABLISSEMENT_PAR"]);}
		$res=$_participants->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["ID_PAR"])){
		$_participants->set_ID_PAR($_POST["ID_PAR"]);
		$res=$_participants->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["ID_PAR"])){$_participants->set_ID_PAR($_POST["ID_PAR"]);}
		if(isset($_POST["NOM_PAR"])){$_participants->set_NOM_PAR($_POST["NOM_PAR"]);}
		if(isset($_POST["PRENOM_PAR"])){$_participants->set_PRENOM_PAR($_POST["PRENOM_PAR"]);}
		if(isset($_POST["E_MAIL_PAR"])){$_participants->set_E_MAIL_PAR($_POST["E_MAIL_PAR"]);}
		if(isset($_POST["TEL_PAR"])){$_participants->set_TEL_PAR($_POST["TEL_PAR"]);}
		if(isset($_POST["GRADE_PAR"])){$_participants->set_GRADE_PAR($_POST["GRADE_PAR"]);}
		if(isset($_POST["SPECIALITE_PAR"])){$_participants->set_SPECIALITE_PAR($_POST["SPECIALITE_PAR"]);}
		if(isset($_POST["UNIVERSITE_PAR"])){$_participants->set_UNIVERSITE_PAR($_POST["UNIVERSITE_PAR"]);}
		if(isset($_POST["ETABLISSEMENT_PAR"])){$_participants->set_ETABLISSEMENT_PAR($_POST["ETABLISSEMENT_PAR"]);}
		$res=$_participants->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["ID_PAR"]) && !empty($_POST["ID_PAR"])){
		$constraint.=" AND ID_PAR='".$_POST["ID_PAR"]."'";
	}

	if(isset($_POST["NOM_PAR"]) && !empty($_POST["NOM_PAR"])){
		$constraint.=" AND NOM_PAR='".$_POST["NOM_PAR"]."'";
	}

	if(isset($_POST["PRENOM_PAR"]) && !empty($_POST["PRENOM_PAR"])){
		$constraint.=" AND PRENOM_PAR='".$_POST["PRENOM_PAR"]."'";
	}

	if(isset($_POST["E_MAIL_PAR"]) && !empty($_POST["E_MAIL_PAR"])){
		$constraint.=" AND E_MAIL_PAR='".$_POST["E_MAIL_PAR"]."'";
	}

	if(isset($_POST["TEL_PAR"]) && !empty($_POST["TEL_PAR"])){
		$constraint.=" AND TEL_PAR='".$_POST["TEL_PAR"]."'";
	}

	if(isset($_POST["GRADE_PAR"]) && !empty($_POST["GRADE_PAR"])){
		$constraint.=" AND GRADE_PAR='".$_POST["GRADE_PAR"]."'";
	}

	if(isset($_POST["SPECIALITE_PAR"]) && !empty($_POST["SPECIALITE_PAR"])){
		$constraint.=" AND SPECIALITE_PAR='".$_POST["SPECIALITE_PAR"]."'";
	}

	if(isset($_POST["UNIVERSITE_PAR"]) && !empty($_POST["UNIVERSITE_PAR"])){
		$constraint.=" AND UNIVERSITE_PAR='".$_POST["UNIVERSITE_PAR"]."'";
	}

	if(isset($_POST["ETABLISSEMENT_PAR"]) && !empty($_POST["ETABLISSEMENT_PAR"])){
		$constraint.=" AND ETABLISSEMENT_PAR='".$_POST["ETABLISSEMENT_PAR"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_participants->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_participants->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>